package com.wxh.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * @ClassName: Test2
 * @Description:
 * @Author wxh
 * @Date: 2019/11/8 16:18
 * @Version V1.0.0
 * @Since 1.8
 */
public class Test2 {
    public static void main(String[] args) throws ParseException {
        String time = "2019-10-10 01:00:00";
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date date = sdf.parse(time);
        Calendar no = Calendar.getInstance();
        no.setTime(date);
        no.set(Calendar.DATE, no.get(Calendar.DATE) - 7);
        Date date2 = no.getTime();
        System.out.println(sdf.format(date2));

        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.add(Calendar.DAY_OF_MONTH, -1);
        Date dBefore = calendar.getTime();
        System.out.println(sdf.format(dBefore));
    }

    public Date getDateBefore(Date d, int day) {
        Calendar no = Calendar.getInstance();
        no.setTime(d);
        no.set(Calendar.DATE, no.get(Calendar.DATE) - day);
        return no.getTime();
    }
}
